package com.aiden.cashbook.charge

import com.aiden.cashbook.bean.Bill
import com.aiden.cashbook.bean.UseType
import com.aiden.cashbook.data.charge.ChargeDataSource
import com.aiden.cashbook.data.charge.ChargeRepository
import javax.inject.Inject

class ChargePresenter @Inject constructor(var mChargeRepository: ChargeRepository): ChargeContract.Presenter {

    lateinit var mChargeView: ChargeContract.View

    override fun chargeAccount(bill: Bill) {
        mChargeRepository.chargeAccount(bill, object : ChargeDataSource.SavedCallback {
            override fun onSavedSuccess() {
                mChargeView.saveSuccess()
            }

            override fun onFailure() {
                mChargeView.saveFailure()
            }

        })
    }

    override fun accountType(type: String) {

        mChargeRepository.accountType(type, object : ChargeDataSource.LoadListCallBack<UseType> {
            override fun onDataLoaded(list: List<UseType>) {
                mChargeView.typeLoadSuccess(list)
            }

            override fun onDataNotAvailable() {
                mChargeView.typeLoadFailure()
            }

        })
    }

    override fun takeView(view: ChargeContract.View) {
        mChargeView = view
    }

    override fun dropView() {
    }
}